﻿using AngleExpress.utils;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace AngleExpress.software
{
    class DuoKai : ISoftware
    {
        public override bool needLogin()
        {
            return false;
        }
        public override void OpenSoftware(string username, string password, string otherParam)
        {
            string exePath = FindDuokaiExePath();
            if (exePath == "")
            {
                throw new Exception("没有找到多开软件安装路径");
            }

            if (!File.Exists(exePath))
            {
                throw new Exception("多开软件安装路径上不存在");
            }

            ProcessStartInfo info = new ProcessStartInfo();
            info.UseShellExecute = true;
            info.FileName = exePath;
            try
            {
                Process pro = Process.Start(info);
                MessageBox.Show("多开软件已在托盘中启动", "提示", MessageBoxButton.OK, MessageBoxImage.Information,
                   MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        string FindDuokaiExePath()
        {
            String[] drivers = Environment.GetLogicalDrives();
            foreach (String driver in drivers)
            {
                try {
                    string exePath = Utils.TraverseDir(driver, driver, "SbieCtrl.exe", 3);
                    if (exePath != "")
                        return exePath;
                }
                catch(Exception e)
                {
                    Console.WriteLine(e.Message);
                    TextLog.Add("FindDuokaiExePath:" + e.Message);
                    TextLog.Add(e.StackTrace);
                    continue;
                }
                
            }
            return "";
        }

        
    }
}
